<template>
	<view class="jie">
		<view class="moneylist">
			<view class="left">
				<view class="money">{{userinfo.jine|capitalize}}</view>
				<view>可用余额</view>
			</view>

			<view class="right">
				<view class="money">{{userinfo.dongjie_jine|capitalize}}</view>
				<view>冻结余额</view>
			</view>
		</view>
		<view class="box">
			<view class="dingdanbox">
				<view class="dingdan">
					<view class="item">
						<view class="con">{{userinfo.today_earning|capitalize}}</view>
						<view class="text">今日收益</view>
					</view>
					<view class="item">
						<view class="con">{{userinfo.today_ordernum|capitalize1}}</view>
						<view class="text">今日订单</view>
					</view>
					<view class="item">
						<view class="con">{{userinfo.total_earning|capitalize}}</view>
						<view class="text">累计收益</view>
					</view>
				</view>
			</view>
		</view>

		<view class="list">
			<view class="title">
				<view class="left">接单列表</view>
			</view>
			<view class="con">
				<view class="content">
					<view class="item" v-for="(item,index) in order" :key="index">
						<view class="left">
							<image :src="item[4]"></image>
						</view>
						<view class="middle">
							<view>商户号 {{item[5]}}</view>
							<view>订单流水号 {{item[6]}}</view>
						</view>
						<view class="right blue1" @tap="qiangdan(item)">抢</view>
					</view>
				</view>
				<view class="zanwu" v-if="order.length==0">
					暂无订单
				</view>
			</view>
		</view>
		

	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	import {sendmsg} from "@/socket.js";
	export default {
		data() {
			return {

			}
		},
		filters: {
			capitalize: function(value) {
				if (value != null) {
					var chazhi = 0;
					chazhi = parseFloat(value).toFixed(2);
					return chazhi;
				} else {
					return 0.00;
				}

			},
			capitalizen: function(value) {
				if (value) {
					var chazhi = 0;
					chazhi = parseFloat(value.jine*1 - value.dongjie_jine*1).toFixed(2);
					return chazhi;
				} else {
					return 0.00;
				}

			},
			capitalize1: function(value) {
				if (value != null) {
					var chazhi = 0;
					chazhi = parseFloat(value).toFixed(0);
					return chazhi;
				} else {
					return 0;
				}

			}
		},
		watch: {
			order(newName, oldName) {
				this.numchange(newName);
			}
		},

		methods: {
			numchange(newName){
				console.log(newName)
				if(newName.length==0){
					console.log()
					// #ifdef APP-PLUS
					this.stopaudio()
						// #endif
					
				}
				else{
					// #ifdef APP-PLUS
					this.ScanAudio();
					// #endif
				}
			},
         qiangdan(item){
			 	// mqtt接单
			 // var data = `23;${this.userinfo.yh_id};${item[2]};${uni.getStorageSync('token')};`;
			 // sendmsg("order_vie",data);
			 // php接单
			 var data = {
			 	token: uni.getStorageSync('token'),
				order_id:item[2]
			 };
			 this.$store.dispatch('takeorder', data).then(res => {
			 	uni.showToast({
			 		title: res.data.msg,
			 		icon: 'none'
			 	});
				if(res.data.code==1){
					var data = {
						token: uni.getStorageSync('token'),
					};
					this.$store.dispatch('orderunderway', data)
				}
			 });
		 }
		},
		computed: mapState({
			userinfo: 'userinfo',
			"order":"order"
		})
	}
</script>

<style lang="scss" scoped src="./index.scss"></style>
